package com.doctcloud.hisinfo.ordadm.controller;

import com.doctcloud.common.core.utils.StringUtils;
import com.doctcloud.common.core.web.domain.AjaxResult;
import com.doctcloud.hisinfo.histable.domain.ordadm.OrdersDo;
import com.doctcloud.hisinfo.ordadm.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ordadm/")
public class OrdersController {
    @Autowired
    private IOrdersService ordersService;

    @PostMapping("/orders/patalllist")
    public AjaxResult listByEntity(@RequestBody OrdersDo request) {
        if (ObjectUtils.isEmpty(request)){
            return AjaxResult.error("空数据无法处理");
        }
        System.out.println(request.toString());

        String patId = request.getPatientId();
        Integer visitId = request.getVisitId();
        List<OrdersDo> list = ordersService.listPatAll(patId,visitId);
        return AjaxResult.success(list);
    }

    @GetMapping("/orders/listbypat")
    public List<OrdersDo> listByParams(@RequestParam("patientId") String patientId,
                                       @RequestParam("visitId") Integer visitId){
        List<OrdersDo> reslist = new ArrayList<>();
        if (StringUtils.isEmpty(patientId)) {
            System.out.println("patientId参数缺失");
            return reslist;
        }
        if (ObjectUtils.isEmpty(visitId)){
            System.out.println("visitId参数缺失");
            return reslist;
        }
        return ordersService.listPatAll(patientId,visitId);
    }
}
